<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>购物车</title>
<script type="text/javascript" src="js/jquery-3.2.1.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript">
	$(function() {
		$(".jian").click(function() {
			var x = $(this).attr("nu");
			x=Number(x);
			var a = $(this).attr("gid");
			var b = $(this).attr("pho");
			x = x - 1;
			$.get("CartServlet", {
				goods_id : a,
				op : 7,
				num : x,
				phone : b
			}, function() {
				location.reload();
			});
		});

		$(".jia").click(function() {
			var x = $(this).attr("nu");
			x=Number(x);
			x=x+1;
			var a = $(this).attr("gid");
			var b = $(this).attr("pho");
			$.get("CartServlet", {
				goods_id : a,
				op : 7,
				num : x,
				phone : b
			}, function() {
				location.reload();
			});
		});
		
		$(".input1").blur(function(){
			var a = $(this).attr("gid");
			var b = $(this).attr("pho");
			 var x = $(this).val();
				$.get("CartServlet", {
					goods_id : a,
					op : 7,
					num : x,
					phone : b
				}, function() {
					location.reload();
				});
			});
		
		$(".jiesuanbtn").click(function(){
			var remark=$(".remark").val();
			var paiduihao = $(this).attr("paiduihao");
			var table = $(this).attr("tb");
			if (confirm("真的为"+table+"桌点菜吗？")) {
				$.get("DingDanServlet", {
					op : 16,
					remark:remark,
					number:paiduihao,
					table_name:table
				}, function() {
					alert("下单成功");
					parent.location = "GoodsServlet?op=9&pagesize=5&curpage=1";
				});
			}
		});
	});
	
	 function RepNumber(obj) {
         var reg = /^[\d]+$/g;
          if (!reg.test(obj.value)) {
              var txt = obj.value;
              txt.replace(/[^0-9]+/, function (char, index, val) {
                 obj.value = val.replace(/\D/g, "");//将非数字字符替换成""
                 var rtextRange = null;
                 if (obj.setSelectionRange) {
                     obj.setSelectionRange(index, index);
                 } else {//支持ie
                     rtextRange = obj.createTextRange();
                     rtextRange.moveStart('character', index);
                     rtextRange.collapse(true);
                     rtextRange.select();
                 }
             })
          }
      }
</script>
<style type="text/css">
body {
	font-size: 12px;
	width: 100%;
	height: auto;
}
</style>
</head>
<body>
	<div style="text-align: center;">
		<h4>购物车</h4>
		<hr>
	</div>
	<table width="100%">
		<c:forEach items="${Goods.cartList}" var="x">
			<tr>
				<td style="text-align: center;">${x.name}</td>
				<td style="width: 50%; text-align: center;">
					<div style="text-align: center;">
						<img src="image/jian.png" width="15px" height="15px" class="jian"
							gid="${x.goodsId}" pho="${x.phone}" nu="${x.num}"> <input
							type="text" value="${x.num}"
							style="width: 40px; margin-left: 10px; text-align: center; margin-top: -30px"
							class="input1" onkeyup="RepNumber(this)"
							gid="${x.goodsId}" pho="${x.phone}" nu="${x.num}"> <img
							src="image/jia.png" width="15px" height="15px" class="jia"
							gid="${x.goodsId}" pho="${x.phone}" nu="${x.num}">
					</div>
				</td>
			</tr>
		</c:forEach>
	</table>
	<hr>
	<span style="vertical-align: top">备注：</span>
	<textarea class="remark"></textarea>
	<div style="text-align: center; margin-top: 10px; padding: 10px">
		<button style="width: 100px; height: 30px; font-size: 14px"
			class="jiesuanbtn" pho="${x.phone}"
			paiduihao="${sessionScope.number}" tb="${sessionScope.table_name}">结算</button>
	</div>
</body>
</html>